package modelo2;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class AdicionaFuncionarioDepartamento {

	public static void main(String[] args) {
		EntityManagerFactory factory = Persistence
				.createEntityManagerFactory("mapeamentoDB");
		EntityManager manager = factory.createEntityManager();

		manager.getTransaction().begin();
		
		Funcionario f = new Funcionario();
		f.setNome("Claudemir Madeira Junior");
		
		Departamento d = new Departamento();
		d.setNome("Contas a Pagar");
		d.getFuncionarios().add(f);
		manager.persist(d);
		manager.persist(f);
		manager.getTransaction().commit();
		
		manager.close();
		factory.close();
	}
}
